import java.awt.*;
import java.awt.event.*;
import java.lang.*;


public class CompteurTest extends Frame {

	//private SharedObject cpto;
	static String myName;
	
	static SharedObject c = null;


	public static void main (String argv[]) {
		if (argv.length != 1) {
			System.out.println("java CompteurTest <name>");
			return;
		}
		myName = argv[0];

		// initialize the system
		Client.init();
		
		// look up the IRC object in the name server
		// if not found, create it, and register it in the name server
		Compteur cpt = null;
		c = Client.lookup("CompteurTest");
		if (c == null) {
			cpt = new Compteur();
			c = Client.create(cpt);
			System.out.println(c.id);
			Client.register("CompteurTest", c);
		}
		c.lock_read();
		cpt.read();
		c.unlock();
		c.lock_write();
		for (int i= 1; i<10; i++){
			try{
				//c.lock_write();
				Compteur cpt1= (Compteur)c.obj;
				cpt1.increment();
				c.obj=cpt1;
				//c.unlock();
				Thread.currentThread().sleep(1000);
			}catch(InterruptedException ie){
				ie.printStackTrace();
			}
		
							
		}
		c.unlock();
		c.lock_read();
		Compteur cpt1= (Compteur) c.obj;
		cpt1.read();
		c.unlock();
	}
}






